package com.smart.campus.web.controller.merchant;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.Pos;
import com.smart.campus.school.service.IPosService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 消费设备Controller
 * 
 * @author Zhihe.Li
 * @date 2020-07-27
 */
@Controller
@RequestMapping("/school/pos")
public class PosController extends BaseController
{
    private String prefix = "school/pos";

    @Autowired
    private IPosService posService;

    @RequiresPermissions("school:pos:view")
    @GetMapping()
    public String pos()
    {
        return prefix + "/pos";
    }

    /**
     * 查询消费设备列表
     */
    @RequiresPermissions("school:pos:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Pos pos)
    {
        startPage();
        List<Pos> list = posService.selectPosList(pos);
        return getDataTable(list);
    }

    /**
     * 导出消费设备列表
     */
    @RequiresPermissions("school:pos:export")
    @Log(title = "消费设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Pos pos)
    {
        List<Pos> list = posService.selectPosList(pos);
        ExcelUtil<Pos> util = new ExcelUtil<Pos>(Pos.class);
        return util.exportExcel(list, "pos");
    }

    /**
     * 新增消费设备
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存消费设备
     */
    @RequiresPermissions("school:pos:add")
    @Log(title = "消费设备", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Pos pos)
    {
        return toAjax(posService.insertPos(pos));
    }

    /**
     * 修改消费设备
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Pos pos = posService.selectPosById(id);
        mmap.put("pos", pos);
        return prefix + "/edit";
    }

    /**
     * 修改保存消费设备
     */
    @RequiresPermissions("school:pos:edit")
    @Log(title = "消费设备", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Pos pos)
    {
        return toAjax(posService.updatePos(pos));
    }

    /**
     * 删除消费设备
     */
    @RequiresPermissions("school:pos:remove")
    @Log(title = "消费设备", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(posService.deletePosByIds(ids));
    }
}
